﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Coldairarrow.Business.Goods;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.Goods;
using Coldairarrow.IBusiness.Goods;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;

namespace Coldairarrow.Api.Controllers.GoodsDetail
{
    [Route("/backstage/[controller]/[action]")]
    public class BKS_GoodsController : BaseApiController
    {
        public BKS_GoodsController(IBTB_GoodsBusiness bTB_GoodsBus, IBTB_HomeBusiness bTB_HomeBusiness)
        {
            _bTB_GoodsBus = bTB_GoodsBus;
            _bTB_HomeBus = bTB_HomeBusiness;
        }
        IBTB_GoodsBusiness _bTB_GoodsBus { get; }

        IBTB_HomeBusiness _bTB_HomeBus;


        /// <summary>
        /// 商品管理列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<BTB_GoodsDto>> GetGoodsList(PageInput<BTB_GoodsDto> input)
        {
            return await _bTB_GoodsBus.GetGoodsList(input);
        }

        /// <summary>
        /// 指定查询
        /// </summary>
        /// <param name="idInput">商品id</param>
        /// <returns></returns>
        [HttpPost]
        public object GetTheData(IdInputDTO idInput)
        {
            return _bTB_GoodsBus.GetTheData(idInput.id);
        }

        #region 提交
        /// <summary>
        /// 添加或修改商品详情
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SaveData(BTB_GoodsDto data)
        {
            if (data.ID.IsNullOrEmpty())
            {
                InitEntity(data);

                await _bTB_GoodsBus.AddThisData(data);
            }
            else
            {
                await _bTB_GoodsBus.UpdateData(data);
            }
        }

        /// <summary>
        /// 删除指定商品详情
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _bTB_GoodsBus.DeleteData(ids);
        }

        /// <summary>
        /// 首页模糊查询
        /// </summary>
        /// <param name="GoodsName"></param>
        /// <returns></returns>
        [HttpPost]
        public List<BTB_Goods> GetGoodsName(string GoodsName)
        {
            return _bTB_HomeBus.GetTheDataName(GoodsName);

        }

        /// <summary>
        /// 查询商品名称-------仓库管理使用
        /// </summary>
        /// <param name="GoodsName"></param>
        /// <returns></returns>
        public async Task<List<BTB_GoodsDto>> GetGoods(string GoodsName)
        {
            return await _bTB_HomeBus.GetGoods(GoodsName);
        }
        #endregion
    }
}